<!DOCTYPE html>
<!-- saved from url=(0063)http://twitter.github.com/bootstrap/examples/sticky-footer.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title>Linked Data Metrics</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script src="js/bgraph.js"></script>
    <!-- CSS -->
    <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
    <style type="text/css">

      /* Sticky footer styles
      -------------------------------------------------- */

      html,
      body {
        height: 100%;
         background-color: #eeeeee;
        /* The html and body elements cannot have any padding or margin. */
      }

      /* Wrapper for page content to push down footer */
      #wrap {
        min-height: 100%;
        height: auto !important;
        height: 100%;
        /* Negative indent footer by it's height */
        margin: 0 auto -60px;
      }

      /* Set the fixed height of the footer here */
      #push,
      #footer {
        height: 60px;
      }
      #footer {
        background-color: #f5f5f5;
      }

      /* Lastly, apply responsive CSS fixes as necessary */
      @media (max-width: 767px) {
        #footer {
          margin-left: -20px;
          margin-right: -20px;
          padding-left: 20px;
          padding-right: 20px;
        }
      }

      /* Custom page CSS
      -------------------------------------------------- */
      /* Not required for template or sticky footer method. */

      .container {
        width: auto;
        max-width: 680px;
      }
      .container .credit {
        margin: 20px 0;
      }

    </style>
    <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">

    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Fav and touch icons -->
    <link rel="shortcut icon" href="http://twitter.github.com/bootstrap/assets/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="http://twitter.github.com/bootstrap/assets/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="http://twitter.github.com/bootstrap/assets/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="http://twitter.github.com/bootstrap/assets/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="http://twitter.github.com/bootstrap/assets/ico/apple-touch-icon-57-precomposed.png">
    

 <script>
var endpoint = "http://data.aalto.fi/sparql";

if(window.location.href.indexOf("?endpoint=")>1) {
	endpoint = "http://data.aalto.fi/sproxy.php?service-uri="+decodeURIComponent(window.location.href.substr(window.location.href.indexOf("?endpoint=")+10))
}

//var openAc =  "http://data.open.ac.uk/query";
//var endpointb = "http://data.uni-muenster.de/sparql";
//var endpoint = "http://data.aalto.fi/sparql";

var bgraph = new BGraph();
var prefix = bgraph.getPrefixes();
google.load("visualization", "1", {packages:["corechart"]});

$(document).ready(function() {

// Number of literals
var qn = "SELECT (COUNT(?o) as ?no) WHERE { ?s ?p ?o . FILTER isLiteral(?o) }";
// Number of empty literals
var qx = "SELECT (COUNT(?o) AS ?no) WHERE { ?s ?p ?o . FILTER isLiteral(?o) FILTER(strlen(str(?o))<1) }";
// Number of subject without type
var q0 = "SELECT (COUNT(?s) AS ?no) WHERE { ?s ?p ?o . FILTER NOT EXISTS { ?s a ?type }}"

var pDeviation = "SELECT ?class (min(?count) as ?min) (avg(?count) as ?avg) (max(?count) as ?max) { {SELECT DISTINCT ?class (count(?p) as ?count)   { ?s ?p ?o . ?s a ?class . } GROUP BY ?s ?class } } GROUP BY ?class";

//var qtotCount = prefix+"SELECT (COUNT(DISTINCT ?s) AS ?sdCount) (COUNT(DISTINCT ?p) AS ?pdCount) (COUNT(DISTINCT ?o) AS ?odCount) WHERE { ?s ?p ?o  }";

//total number of triples
var qtCount = prefix+"SELECT (COUNT(*) AS ?tCount)  WHERE { ?s ?p ?o  }";

//total number of distinct subject nodes
//var qsdCount = prefix+"SELECT (COUNT(DISTINCT ?s) AS ?sdCount) WHERE { ?s ?p ?o }";
// total number distinct predicates
var qpdCount = prefix+"SELECT (COUNT(DISTINCT ?p) AS ?pdCount) WHERE { ?s ?p ?o }"; 

var qpdCountTest = prefix+"SELECT (COUNT(DISTINCT ?p) AS ?pdCountTest) WHERE { ?s ?p ?o } GROUP BY ?p";
 
//total number of distinct subject nodes
//var qodCount = prefix+"SELECT (COUNT(DISTINCT ?o) AS ?odCount) WHERE { ?s ?p ?o }";

// Total number of distinct literals
var qlitCount = prefix+"SELECT (COUNT(DISTINCT ?o) AS ?dlitCount) (COUNT(?o) AS ?litCount) WHERE { ?s a ?type . ?s ?p ?o  filter(!isLiteral(?o)) }";
// Number of recurring literals
var ql = "SELECT DISTINCT (COUNT(?o) as ?no) WHERE { ?s ?p ?o . FILTER isLiteral(?o) } GROUP BY ?o HAVING(?no > 1)";
// Number of literals by domain
var qlitDom = prefix+"SELECT ?localName (COUNT(?p) AS ?count) WHERE { ?s a ?type . ?s ?p ?o . FILTER isLiteral(?o) BIND(STR(?p) AS ?pn) BIND(REPLACE(?pn, '[^#|^/]*$', '') AS ?domain) BIND(STRAFTER(?pn,?domain) AS ?localName) } GROUP BY ?domain ?localName ORDER BY ?count";

// predicate domain names vs. number of triples
var q7 = prefix+"SELECT str(?domain) count(?s) WHERE { ?s ?p ?o . BIND(afn:namespace(?p) AS ?domain) } GROUP BY ?domain";
// subject domain names vs. number of distinct subjects
var q8 = prefix+"SELECT str(?domain) count(DISTINCT ?s) WHERE { ?s ?p ?o . BIND(afn:namespace(?s) AS ?domain) } GROUP BY ?domain";
// properties and number of triples
var q9 = prefix+"SELECT ?p (COUNT(?s) AS ?count ) { ?s ?p ?o } GROUP BY ?p ORDER BY ?count";
// Type of literals
var q10 = prefix+"SELECT ?type (count(?literal) as ?count)  WHERE { ?any ?property ?literal . FILTER isLiteral(?literal) BIND(datatype(?literal) as ?type) BIND(afn:namespace(?type) as ?namespace) } GROUP BY ?type ORDER BY ?count";

//var q4 = prefix+"SELECT ?class (COUNT(?s) AS ?count) { ?s a ?class } GROUP BY ?class ORDER BY ?count";
//var q5 = prefix+"SELECT srt(?p) (COUNT(DISTINCT ?s ) AS ?Subjects ) { ?s ?p ?o } GROUP BY ?p ORDER BY desc(?Subjects)";


// total number of distinct classes and instances with a type
var qciCount = prefix+"SELECT (COUNT(?instance) AS ?iCount) (COUNT(distinct ?type) AS ?cCount) WHERE { ?instance a ?type }";
// Importance of a class (Ci / I)
var qibycCount = prefix+"SELECT ?type (COUNT(?instance) AS ?icCount) WHERE { ?instance a ?type } GROUP BY ?type ORDER BY ?icCount";

// total number distinct property usage
var qpdCount = prefix+"SELECT (COUNT(?p) AS ?puCount) (COUNT(DISTINCT ?p) AS ?pduCount) WHERE { ?instance a ?type . ?instance ?p ?o }"; 
var qibypCount = prefix+"SELECT ?p (COUNT(?p) AS ?puCount) WHERE { ?instance a ?type . ?instance ?p ?o FILTER(?p != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>)} GROUP BY ?p ORDER BY ?puCount";
var pDeviation = "SELECT ?class (min(?count) as ?min) (avg(?count) as ?avg) (max(?count) as ?max) { {SELECT ?class (count(?p) AS ?count)   { ?s ?p ?o . ?s a ?class . } GROUP BY ?s ?class } } GROUP BY ?class ORDER BY desc(?avg)";
// predicate domain names vs. number of triples
var qpDom = prefix+"SELECT ?domain (COUNT(?p) AS ?pCount) WHERE { ?s a ?type . ?s ?p ?o . BIND(REPLACE(STR(?p), '[^#|^/]*$', '') AS ?domain) } GROUP BY ?domain ORDER BY ?count";

// Total number of distinct literals
var qlitCount = prefix+"SELECT (COUNT(DISTINCT ?o) AS ?dlitCount) (COUNT(?o) AS ?litCount) WHERE { ?s a ?type . ?s ?p ?o  filter(!isLiteral(?o)) }";
// Number of recurring literals

var ql = "SELECT DISTINCT (COUNT(?o) as ?no) WHERE { ?s ?p ?o . FILTER isLiteral(?o) } GROUP BY ?o HAVING(?no > 1)";
// Number of literals by domain
var qlitDom = prefix+"SELECT ?domain (COUNT(?o) AS ?count) WHERE { ?s a ?type . ?s ?p ?o . FILTER isLiteral(?o) BIND(REPLACE(STR(?p), '[^#|^/]*$', '') AS ?domain) } GROUP BY ?domain ORDER BY ?count";
var qlitType = prefix+"SELECT ?type (COUNT(?o) AS ?count) WHERE { ?s a ?class . ?s ?p ?o . FILTER isLiteral(?o) BIND(datatype(?o) as ?type) } GROUP BY ?type ORDER BY ?count";

var graphs = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } }";

var ajaxTime;



function ajaxQuery(q) {
	return $.ajax({
		headers: { Accept : 'application/sparql-results+json' },
        url: endpoint,
        dataType: 'json',
        data: { query: q, format: 'json'}
    });
}

function plotText(queryString) {
	ajaxTime = new Date().getTime();
	return ajaxQuery(queryString).done(function(data) {
	 console.log(queryString);
	 console.log((new Date().getTime()-ajaxTime)/1000 +" sekuntia");
	// data = $.parseJSON(data); // For debugging only
	if(data.results.bindings.length>0) {
		var vars = data.head.vars;
        data = data.results.bindings;
		
		for(item in data) {
            for(id in vars) {
                $("#"+vars[id]).html(data[item][vars[id]].value);
            }
		}
		
	} else $("#error").html("No results found");
	});
}

function plotPie(queryString,elem) {
	return ajaxQuery(queryString).done(function(data) {
	// data = $.parseJSON(data); // For debugging only
	if(data.results.bindings.length>0) {
		console.log(data);
		var data = new google.visualization.DataTable(bgraph.SparqlJSON2GoogleJSON(data));
		console.log(data);
		var viz = new google.visualization.PieChart($(elem)[0]);
				
		var options = {
			is3D:true,
			height: 300,
			width:500,
			chartArea:{left:0,top:0},
        	backgroundColor: {fill:"#efefef"},
        	legendTextStyle:{color:"#222", fontSize:9, bold:true},
       		legend:"right",
       		theme:"maximized"
			};
			
		viz.draw(data,options);
		
	}});
}

function plotStacked(queryString,elem) {
	return ajaxQuery(queryString).done(function(data) {
	// data = $.parseJSON(data); // For debugging only
	if(data.results.bindings.length>0) {
				
		var data = new google.visualization.DataTable(bgraph.SparqlJSON2GoogleJSON(data));
		var viz = new google.visualization.ColumnChart($(elem)[0]);
		
		var options = '{"backgroundColor": {"fill":"#efefef"},"height":300,"width":500,"focusTarget":"category","hAxis":{"logScale":true,"useFormatFromData":true},"legend":"right","vAxes":[{"useFormatFromData":true,"viewWindowMode":"pretty"},{"useFormatFromData":true,"viewWindowMode":"pretty"}],"isStacked":true,"animation":{"duration":500},"booleanRole":"certainty"}';
		//var options = '{"backgroundColor": {"fill":"#efefef"},"height":300,"width":500,"hAxis":{"logScale":true,"useFormatFromData":true},"vAxes":[{"useFormatFromData":true,"viewWindowMode":"pretty"},{"useFormatFromData":true,"viewWindowMode":"pretty"}],"animation":{"duration":500},"booleanRole":"certainty","legend":"none","focusTarget":"category","theme":"maximized"}';
	
		options = $.parseJSON(options);
		
		viz.draw(data,options);
		
	}});
}

function plotBar(queryString,elem) {
	return ajaxQuery(queryString).done(function(data) {
	// data = $.parseJSON(data); // For debugging only
	if(data.results.bindings.length>0) {
				
		var data = new google.visualization.DataTable(bgraph.SparqlJSON2GoogleJSON(data));
		var viz = new google.visualization.ColumnChart($(elem)[0]);
		
		var options = '{"backgroundColor": {"fill":"#efefef"},"height":300,"width":500,"hAxis":{"useFormatFromData":true},"vAxes":[{"logScale":true,"useFormatFromData":true,"viewWindowMode":"pretty"},{"useFormatFromData":true,"viewWindowMode":"pretty"}],"animation":{"duration":500},"booleanRole":"certainty","legend":"none","focusTarget":"category","theme":"maximized"}';
	
		options = $.parseJSON(options);
		
		viz.draw(data,options);
		
	}});
}

function plotRadar(queryString,elem) {
	return ajaxQuery(queryString).done(function(data) {
	// data = $.parseJSON(data); // For debugging only
	if(data.results.bindings.length>0) {
				
		var data = new google.visualization.DataTable(bgraph.SparqlJSON2GoogleJSON(data));
	//	var viz = new google.visualization.ChartWrapper($.parseJSON('{"containerId":"","options":{"backgroundColor": {"fill":"#efefef"},"height":300,"width":500,"hAxis":{"useFormatFromData":true,"viewWindowMode":"pretty","viewWindow":{"max":null,"min":null},"minValue":null,"maxValue":null},"title":"","vAxes":[{"useFormatFromData":true,"viewWindowMode":"pretty","viewWindow":{"max":null,"min":null},"minValue":null,"maxValue":null},{"useFormatFromData":true,"viewWindowMode":"pretty","viewWindow":{"max":null,"min":null},"minValue":null,"maxValue":null}],"cht":"rs","booleanRole":"certainty","colors":["#3366CC","#DC3912","#FF9900","#109618","#990099","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#651067","#329262","#5574A6","#3B3EAC","#B77322","#16D620","#B91383","#F4359E","#9C5935","#A9C413","#2A778D","#668D1C","#BEA413","#0C5922","#743411"],"chm":"","valuesSuffix":"","chxs":"1NLiterals **","valuesPrefix":"Literals ","min":null,"max":null,"legend":"none"},"state":{},"view":{"columns":[{"calc":"emptyString","sourceColumn":0,"type":"string"},0]},"chartType":"ImageChart"}'));
		var viz = new google.visualization.ImageChart($(elem)[0]);
		var options = '{"containerId":"rlit","hAxis":{"useFormatFromData":true,"viewWindowMode":"pretty"},"vAxes":[{"useFormatFromData":true,"viewWindowMode":"pretty"},{"useFormatFromData":true,"viewWindowMode":"pretty"}],"cht":"rs","booleanRole":"certainty","colors":["#3366CC","#DC3912","#FF9900","#109618","#990099","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#651067","#329262","#5574A6","#3B3EAC","#B77322","#16D620","#B91383","#F4359E","#9C5935","#A9C413","#2A778D","#668D1C","#BEA413","#0C5922","#743411"],"backgroundColor":"#cccccc","legend":"none","showValueLabels":true,"valuesSuffix":" literals","chxs":"1N** literals"}';
		options = $.parseJSON(options);
		
		viz.draw(data,options);
		
	}});
}




//plotText(qsdCount).done(function() {
//plotText(qpdCount).done(function() {
//plotText(qodCount).done(function() {
//plotText(qlitCount).done(function() {
//})})})});

google.setOnLoadCallback(function() {
	
plotText(qciCount).done(function() {
plotPie(qibycCount,"#cPie").done(function() {
plotText(qpdCount).done(function() {
plotPie(qibypCount,"#pPie").done(function() {
plotStacked(pDeviation,"#pDev").done(function() {
plotPie(qpDom,"#pDom").done(function() {
plotText(qlitCount).done(function() {
$("#litRe").html((($("#dlitCount").html()/$("#litCount").html())*100).toFixed(1)+"%");
plotPie(qlitDom,"#litDom").done(function() {
plotPie(qlitType,"#litType").done(function() {
})})})})})})})})});
	
	
	
	
});

$('#endpoint').click(function() {
 this.contentEditable='true';
});
 
$('#endpoint').focusout(function(){
	this.contentEditable='false';
	window.location.href=location.protocol + '//' + location.host + location.pathname+"?endpoint="+this.innerHTML;
});


});



</script>
</head>

<body>


    <!-- Part 1: Wrap all page content here -->
    <div id="wrap">

      <!-- Begin page content -->
      <div class="container">
        <div class="page-header">
          <h1>Linked data metrics</h1>
          <h5><i>Endpoint url:</i> <span id="endpoint">http://data.aalto.fi/sparql</span><i class="icon-edit"></i></h5>
        </div>
        
        
        <h3>Class usage</h3>
        <div class="row"><span class="span3">Count of classes</span><span class="span3" id="cCount"><img src="img/loadstat.gif" alt="loading ..."/></span></div>
        <div class="row"><span class="span3">Count of instances</span><span class="span3" id="iCount"><img src="img/loadstat.gif" alt="loading ..."/></span></div>
        <div class="row"><span class="span3"><h5>Importance of a class</h5></span></div>
        <div class="row" id="cPie"><img style="margin-left:30px;" src="img/loadpie.gif" alt="loading ..."/></div>
        
        <h3>Property usage</h3>
        <div class="row"><span class="span3">Count of properties</span><span class="span3" id="pduCount"><img src="img/loadstat.gif" alt="loading ..."/></span></div>
        <div class="row"><span class="span3">Total property usage</span><span class="span3" id="puCount"><img src="img/loadstat.gif" alt="loading ..."/></span></div>
        <div class="row"><span class="span3"><h5>Importance of a property</h5></span></div>
        <div class="row" id="pPie"><img style="margin-left:30px;" src="img/loadpie.gif" alt="loading ..."/></div>
        <div class="row"><span class="span3"><h5>Property deviation</h5></span></div>
        <div class="row" id="pDev"><img style="margin-left:30px;" src="img/loadpie.gif" alt="loading ..."/></div>
        <div class="row"><span class="span3"><h5>Vocabulary usage</h5></span></div>
        <div class="row" id="pDom"><img style="margin-left:30px;" src="img/loadpie.gif" alt="loading ..."/></div>
        
        <h3>Literal usage</h3>
        <div class="row"><span class="span3">Count of literals</span><span class="span3" id="litCount"><img src="img/loadstat.gif" alt="loading ..."/></span></div>
        <div class="row"><span class="span3">Distinct literals</span><span class="span3" id="dlitCount"><img src="img/loadstat.gif" alt="loading ..."/></span></div>
        <div class="row"><span class="span3">Literal redundancy</span><span class="span3" id="litRe"><img src="img/loadstat.gif" alt="loading ..."/></span></div>
        <div class="row"><span class="span3"><h5>Literals by properties</h5></span></div>
        <div class="row" id="litDom"><img style="margin-left:30px;" src="img/loadpie.gif" alt="loading ..."/></div>
        <div class="row"><span class="span3"><h5>Literals by datatypes</h5></span></div>
        <div class="row" id="litType"><img style="margin-left:30px;" src="img/loadpie.gif" alt="loading ..."/></div>
      </div>

      <div id="push"></div>
    </div>

    <div id="footer">
      <div class="container">
        <p class="muted credit">Linked Open Aalto Quality Metrics</p>
      </div>
    </div>


    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
   <!-- <script src="./Sticky footer · Twitter Bootstrap_files/jquery.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-transition.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-alert.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-modal.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-dropdown.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-scrollspy.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-tab.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-tooltip.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-popover.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-button.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-collapse.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-carousel.js"></script>
    <script src="./Sticky footer · Twitter Bootstrap_files/bootstrap-typeahead.js"></script> -->

  

</body></html>
